home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / haeberli / tools / grid.c < prev    next >
C/C++ Source or Header  |  1994-08-01  |  2KB  |  97 lines

  1. /*
  2.  * Copyright 1991, 1992, 1993, 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. /*
  18.  *     grid -
  19.  *        Draw a 10 by 10 grid. This is useful for aligning
  20.  *    a camera to the display.
  21.  *
  22.  *                Paul Haeberli - 1986
  23.  */
  24. #include <gl/gl.h>
  25. #include <gl/device.h>
  26.  
  27. int drawit();
  28.  
  29. main()
  30. {
  31.     short val;
  32.  
  33.     makewindow();
  34.     drawit();
  35.     while(1)
  36.     switch(qread(&val)) {
  37.         case REDRAW:
  38.         drawit();
  39.         break;
  40.         case LEFTMOUSE:
  41.         case RIGHTMOUSE:
  42.         case KEYBD:
  43.         case ESCKEY:
  44.         exit(0);
  45.         break;
  46.     }
  47. }
  48.  
  49. drawit()
  50. {
  51.     reshapeviewport();
  52.     ortho2(0.0,1.0,0.0,1.0);
  53.     pushmatrix();
  54.     color(0);
  55.     clear();
  56.     color(7);
  57.     drawgrid(10,10);
  58.     popmatrix();
  59. }
  60.  
  61. /*
  62.  *    Make a grid.
  63.  *
  64.  */
  65. drawgrid(xdivs,ydivs)
  66. int xdivs, ydivs;
  67. {
  68.     int i;
  69.     float x, y;
  70.  
  71.     for(i=1; i<xdivs; i++) {
  72.     x = (float)i/xdivs;
  73.     move2(x,0.0);
  74.     draw2(x,1.0);
  75.     }
  76.     for(i=1; i<ydivs; i++) {
  77.     y = (float)i/ydivs;
  78.     move2(0.0,y);
  79.     draw2(1.0,y);
  80.     }
  81. }
  82.  
  83. makewindow() 
  84. {
  85.     long xmaxscreen, ymaxscreen;         
  86.  
  87.     xmaxscreen = getgdesc(GD_XPMAX);
  88.     ymaxscreen = getgdesc(GD_YPMAX);
  89.     noborder();
  90.     prefposition(0, xmaxscreen, 0, ymaxscreen);
  91.     winopen ("grid");
  92.     qdevice(KEYBD);
  93.     qdevice(ESCKEY);
  94.     qdevice(RIGHTMOUSE);
  95.     qdevice(LEFTMOUSE);
  96. }
  97.